using System;
using System.Security.Cryptography;
using System.Text;
namespace Framework
{
    public static partial class Utils
    {
        public static class Encrypt
        {
            /// <summary>
            /// 异或操作
            /// </summary>
            /// <param name="bytes">要操作的数组</param>
            /// <param name="encryptBytes">异或数组</param>
            /// <param name="startIndex">开始位置</param>
            /// <param name="length">异或的长度</param>
            public static void XorSelf(byte[] bytes, byte[] encryptBytes, int startIndex = 0, int length = 100)
            {
                if (bytes == null) return;
                if (startIndex < 0)
                {
                    startIndex = 0;
                }
                if (startIndex >= bytes.Length)
                {
                    return;
                }
                if (encryptBytes == null || encryptBytes.Length < 1) return;
                if (length < 1)
                {
                    length = encryptBytes.Length;
                }
                if (startIndex + length > bytes.Length)
                {
                    length = bytes.Length - startIndex;
                }
                int j = 0;
                int c = encryptBytes.Length;
                for (var i = startIndex; i < length; i++)
                {
                    bytes[i] ^= encryptBytes[j++];
                    j %= c;
                }
            }
        }
    }
}